//
//  UIColor+SMColor.m
//  lishiminOC
//
//  Created by p2p on 16/10/11.
//  Copyright © 2016年 p2p. All rights reserved.
//

#import "UIColor+SMColor.h"

@implementation UIColor (SMColor)

/**
 将16进制颜色值转换为RGB值 默认alpha为1
 
 @param hexColor 16进制颜色值
 
 @return UIColor
 */
+ (UIColor *)colorWithHex:(long)hexColor{
    return [UIColor colorWithHex:hexColor alpha:1.];
}

/**
 将16进制颜色值转换为RGB值
 
 @param hexColor 16进制颜色值
 @param opacity  alpha
 
 @return UIColor
 */
+ (UIColor *)colorWithHex:(long)hexColor alpha:(float)opacity{
    
    float red = ((float)((hexColor & 0xFF0000) >> 16))/255.0;
    float green = ((float)((hexColor & 0xFF00) >> 8))/255.0;
    float blue = ((float)(hexColor & 0xFF))/255.0;
    return [UIColor colorWithRed:red green:green blue:blue alpha:opacity];
}

/**
 随机取颜色值
 
 @return UIColor
 */
+ (UIColor *)randomColor{
    CGFloat hue = (arc4random() % 256 / 256.0);
    CGFloat saturation = (arc4random() % 128 / 256.0) + 0.5;
    CGFloat brightness = (arc4random() % 128 / 256.0) + 0.5;
    UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
    return color;
}
@end
